{% extends "base.html" %}
{% block title %}发布新帖子 - Online Judge{% endblock %}

{% block content %}
<div class="max-w-3xl mx-auto py-6">
  <div class="bg-white rounded-lg shadow p-6">
    <h1 class="text-xl font-bold mb-6">发布新帖子</h1>

    {% with messages = get_flashed_messages(with_categories=true) %}
      {% if messages %}
        <div class="mb-6 space-y-2">
          {% for category, msg in messages %}
            <div class="px-4 py-3 rounded-lg text-sm {% if category == 'danger' %}bg-danger/10 border border-danger/30 text-danger/80{% else %}bg-success/10 border border-success/30 text-success/80{% endif %}">
              {{ msg }}
            </div>
          {% endfor %}
        </div>
      {% endif %}
    {% endwith %}

    <form method="POST" class="space-y-6">
      <!-- 使用修正后的变量名 -->
      <input type="hidden" name="csrf_token" value="{{ csrf_token_value }}">

      <div>
        <label for="title" class="block text-sm font-medium text-gray-700 mb-1">帖子标题</label>
        <input 
          type="text" 
          id="title" 
          name="title" 
          placeholder="请输入清晰的标题（如：如何解决Python超时问题？）" 
          class="form-input w-full"
          required
        >
      </div>

      <div>
        <label for="content" class="block text-sm font-medium text-gray-700 mb-1">帖子内容</label>
        <textarea 
          id="content" 
          name="content" 
          rows="10" 
          placeholder="请详细描述你的问题或分享的内容..." 
          class="form-input w-full resize-none"
          required
        ></textarea>
      </div>

      <div class="flex justify-end space-x-3 pt-4 border-t">
        <a href="{{ url_for('forum_index') }}" class="btn-secondary">取消</a>
        <button type="submit" class="btn-primary">
          <i class="fa fa-paper-plane mr-2"></i>发布帖子
        </button>
      </div>
    </form>
  </div>
</div>
{% endblock %}